import { DomWarBeaOtherPartBase } from "./DomWarBeaOtherPartBase";
import { ObjCreate } from "../../../common/ObjCreate";
import { Language } from "../../../../../../extend/language/Language";
import { GlobalStyle } from "../../../../../common/global/GlobalStyle";
import { ImagesConst } from "../../../../resource/ImagesConst";
import { CampForceBarCellRender } from "./CampForceBarCellRender";
import { EDominionCountryForce } from "../../../../../../Message/Public/EDominionCountryForce";
import { SDominionCityInfo } from "../../../../../../Message/Public/SDominionCityInfo";
import { DomWarConst } from "../../DomWarConst";
import { ClockManager } from "../../../../manager/ClockManager";
import { SecTimer } from "../../../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../../../com/gengine/core/frame/TimerType";
import { Cache } from "../../../../cache/Cache";
import { RemainTimeTool } from "../../../award/RemainTimeTool";
import { GlobalClass } from "../../../../../../com/mui/core/GlobalClass";
import { GTextFiled } from "../../../../../../com/mui/controls/GTextFiled";
//class WorldForceRightPart
    
    export  class WorldForceRightPart extends DomWarBeaOtherPartBase
    {
        constructor(arg1: string="", arg2: Boolean=true, arg3: string="", arg4: number=590, arg5: number=480)
        {
            super(arg1, arg2, arg3, arg4, arg5);
            return;
        }

        protected /* override */ configUI(): void
        {
            super.configUI();
            this._partBgImg.y = 60;
            _partBgImg.height = 275;
            var loc1=18;
            var loc2=70;
            var loc3=62;
            var loc4=18;
            var loc5;
            (loc5 = ObjCreate.createGTextField(Language.getString(90640) + ":", 15, 40, 100, 20, this)).autoSize = "left";
            this._selectCityTimeTxt = ObjCreate.createGTextField("00: 00: 00", loc5.x + loc5.width + 2, 40, 100, 20, this, GlobalStyle.textFormat2);
            this._selectCityTimeTxt.autoSize = "left";
            ObjCreate.createGTextField(Language.getString(90641) + ":", loc1, loc3, 100, 20, this);
            loc3 = loc3 + loc4;
            this._campForceTxt = ObjCreate.createGTextField(Language.getString(90617), loc2, loc3, 100, 20, this, GlobalStyle.textFormat2);
            loc3 = loc3 + 20;
            ObjCreate.createBg(17, loc3, 176, 2, this, ImagesConst.SplitLine);
            loc3 = loc3 + 4;
            ObjCreate.createGTextField(Language.getString(90628) + ":", loc1, loc3, 100, 20, this);
            loc3 = loc3 + loc4;
            this._selfNationPowerTxt = ObjCreate.createGTextField("", loc2, loc3, 100, 20, this, GlobalStyle.textFormat2);
            this._selfNationPowerTxt.autoSize = "left";
            loc3 = loc3 + 20;
            ObjCreate.createBg(17, loc3, 176, 2, this, ImagesConst.SplitLine);
            loc3 = loc3 + 4;
            ObjCreate.createGTextField(Language.getString(90630) + ":", loc1, loc3, 100, 20, this);
            loc3 = loc3 + loc4;
            this._myCityListTxt = ObjCreate.createGTextField(Language.getString(27757), loc2, loc3, 100, 20, this, GlobalStyle.textFormat5);
            this._myCityListTxt.autoSize = "left";
            loc3 = loc3 + 20;
            ObjCreate.createBg(17, loc3, 176, 2, this, ImagesConst.SplitLine);
            loc3 = loc3 + 4;
            ObjCreate.createGTextField(Language.getString(90643) + ":", loc1, loc3, 100, 20, this);
            loc3 = loc3 + loc4;
            this._moneyTxt1 = ObjCreate.createGTextField("", loc2, loc3, 100, 20, this, GlobalStyle.textFormat2);
            this._moneyTxt1.autoSize = "left";
            loc3 = loc3 + loc4;
            loc3 = loc3 + 30;
            ObjCreate.createBg(17, loc3, 176, 2, this, ImagesConst.SplitLine);
            loc3 = loc3 + 4;
            var loc6;
            (loc6 = ObjCreate.createGTextField("", 28, 268, 100, 20, this, GlobalStyle.textFormat5)).multiline = true;
            loc6.autoSize = "left";
            loc6.htmlText = "<font leading=\'2\'>" + Language.getString(90626) + "</font>";
            this._nextAtkCityTxt = ObjCreate.createGTextField("", 36, 456, 100, 20, this, GlobalStyle.textFormat5);
            this._nextAtkCityTxt.autoSize = "left";
            this.createCampForce();
            return;
        }

        /* internal  */createCampForce(): void
        {
            var loc4=null;
            this._cellList = new Array<any>();
            this._campForceData = this.initCampForceData();
            var loc1=3;
            var loc2=1;
            var loc3=this._campForceData;
            this._campForceCnt = new Object /* flash.display.Sprite */();
            this.addChild(this._campForceCnt);
            this._campForceCnt.x = 10;
            this._campForceCnt.y = 390;
            var loc5=loc3.length;
            var loc6=0;
            var loc7=0;
            var loc8=0;
            while (loc8 < loc5) 
            {
                loc4 = new CampForceBarCellRender();
                this._campForceCnt.addChild(loc4);
                loc4.data = loc3[loc8];
                loc4.x = int(loc8 / loc1) * (loc4.width + loc6);
                loc4.y = loc8 % loc1 * (loc4.height + loc7);
                this._cellList.push(loc4);
                ++loc8;
            }
            return;
        }

        /* internal  */initCampForceData(): Array<any>
        {
            var loc1=[EDominionCountryForce._EDominionForceImmortal, EDominionCountryForce._EDominionForceHumanWorld, EDominionCountryForce._EDominionForceDevil];
            var loc2=[];
            var loc3={};
            var loc4=0;
            while (loc4 < loc1.length) 
            {
                loc3 = {};
                loc3.camp = loc1[loc4];
                loc3.num = 0;
                loc3.max = 0;
                loc2.push(loc3);
                ++loc4;
            }
            return loc2;
        }

        public /* override */ update(arg1: Object): void
        {
            this.cityInfo = arg1 as SDominionCityInfo;
            if (this.cityInfo != null) 
            {
                this._campForceTxt.text = DomWarConst.getCampName(this.cityInfo.force);
                this._moneyTxt1.text = Language.getString(90625) + ":" + this.cityInfo.source;
                this._myCityListTxt.text = this.cityInfo.usedSource.toString();
                this._selfNationPowerTxt.text = this.cityInfo.combat.toString();
                this.updateCampForce();
            }
            return;
        }

        /* internal  */updateCampForce(): void
        {
            var loc1=null;
            this.updateCampForceData();
            var loc2=0;
            while (loc2 < this._cellList.length) 
            {
                loc1 = this._cellList[loc2];
                loc1.data = this._campForceData[loc2];
                ++loc2;
            }
            return;
        }

        /* internal  */updateCampForceData(): void
        {
            var loc4=null;
            var loc7=0;
            var loc1=[];
            var loc2={};
            var loc3=this.cityInfo.dominionCitys.length;
            var loc5=new Map<any, any> /* flash.utils.Dictionary */();
            var loc6=0;
            while (loc6 < loc3) 
            {
                loc4 = this.cityInfo.dominionCitys[loc6];
                loc7 = 0;
                while (loc7 < this._campForceData.length) 
                {
                    loc2 = this._campForceData[loc7];
                    if (loc2.camp == loc4.force) 
                    {
                        if (!loc5[loc2.camp]) 
                        {
                            loc2.num = 0;
                            loc5[loc2.camp] = true;
                        }
                        var loc8;
                        var loc9=((loc8 = loc2).num + 1);
                        loc8.num = loc9;
                        loc2.max = loc3;
                        break;
                    }
                    ++loc7;
                }
                ++loc6;
            }
            return;
        }

        /* internal  */get nowDate(): Date
        {
            return ClockManager.instance.nowDate;
        }

        /* internal  */startTimer(): void
        {
            if (!this._secTimer) 
            {
                this._secTimer = new SecTimer(1);
                this._secTimer.addListener(TimerType.ENTERFRAME, this.onTimerRun);
            }
            this._secTimer.reset();
            this._secTimer.start();
            return;
        }

        /* internal  */onTimerRun(arg1: SecTimer): void
        {
            this.updateSelectCityTime();
            this.updateProgressTime();
            return;
        }

        /* internal  */stopTimer(): void
        {
            if (this._secTimer) 
            {
                this._secTimer.stop();
            }
            return;
        }

        /* internal  */updateSelectCityTime(): void
        {
            var loc1=NaN;
            if (Cache.instance.dominionBea.isChooseCity()) 
            {
                loc1 = Cache.instance.dominionBea.dateState.endDate.time - this.nowDate.time;
                loc1 = loc1 / 1000;
                this._selectCityTimeTxt.text = RemainTimeTool.getRemainTimeBySeconds(loc1);
            }
            return;
        }

        /* internal  */updateProgressTime(): void
        {
            var loc2=NaN;
            var loc1="";
            if (Cache.instance.dominionBea.isChooseCity()) 
            {
                loc1 = Language.getString(90640) + ":";
            }
            else if (Cache.instance.dominionBea.isAuctioning()) 
            {
                loc1 = Language.getString(90667) + ":";
            }
            else if (Cache.instance.dominionBea.isInUnion()) 
            {
                loc1 = Language.getString(90668) + ":";
            }
            else if (Cache.instance.dominionBea.canOpenSiege()) 
            {
                loc1 = Language.getString(90671) + ":";
            }
            if (Cache.instance.dominionBea.dateState && !(loc1 == "")) 
            {
                loc2 = Cache.instance.dominionBea.dateState.endDate.time - this.nowDate.time;
                loc2 = loc2 / 1000;
                this._nextAtkCityTxt.text = loc1 + RemainTimeTool.getRemainTimeBySeconds(loc2);
            }
            else 
            {
                this._nextAtkCityTxt.text = "";
            }
            return;
        }

        protected /* override */ onImageLoaded(): void
        {
            super.onImageLoaded();
            _titleTxtImg2.bitmapData = GlobalClass.getBitmapData(ImagesConst.DWBTxtImage_worldForce);
            _titleTxtImg2.y = _titleTxtImg2.y - 10;
            this._titleBg2.y = this._titleBg2.y - 10;
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this.stopTimer();
            return;
        }

        public /* override */ show(arg1: Object /* flash.display.DisplayObjectContainer */): void
        {
            super.show(arg1);
            this.startTimer();
            return;
        }

        /* internal */ /* var */_selectCityTimeTxt: GTextFiled;

        /* internal */ /* var */_campForceTxt: GTextFiled;

        /* internal */ /* var */_selfNationPowerTxt: GTextFiled;

        /* internal */ /* var */_myCityListTxt: GTextFiled;

        /* internal */ /* var */_moneyTxt1: GTextFiled;

        /* internal */ /* var */_moneyTxt2: GTextFiled;

        /* internal */ /* var */_nextAtkCityTxt: GTextFiled;

        /* internal */ /* var */_campForceCnt: Object /* flash.display.Sprite */;

        /* internal */ /* var */_cellList: Array<any>;

        /* internal */ /* var */_campForceData: Array<any>;

        /* internal */ /* var */_secTimer: SecTimer;

        /* internal */ /* var */cityInfo: SDominionCityInfo;
    }
